const paths = require.context('./', true, /^\.\/[\s\S]+\/*\.js$/)
export const requireFolderName = (r, exinclude = [], include = [], fileType = 'index') => {
  const contents = {}
  const paths = exinclude.length ? r.keys().filter(p => !exinclude.includes(p)) : include.length ? r.keys().filter(p => include.includes(p)) : []

  for (const p of paths) {
    const fn = r(p).default || r(p)
    const _array = p.split('/')
    const index = _array.findIndex((item) => item === fileType)
    const nameIndex = index !== -1 && _array.length > 2 ? index - 1 : _array.length - 1
    const name = _array[nameIndex].split('.')[0]
    contents[name] = fn
  }
  return contents
}
const configs = requireFolderName(
  paths,
  ['./index.js', './defaultSettings.js', './plugin.config.js']
)

console.log(configs)
